<template>
  <div class="wrap">
    <el-card class="line-chart card"
             :body-style="{ height:'100%', padding:'0' }">
      <div id="myline"></div>
    </el-card>
    <el-card class="bar-chart card"
             :body-style="{ height:'100%', padding:'0' }">
      <div id="mybar"></div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  mounted() {
    this.myline();
    this.mybar();
  },
  methods: {
    myline() {
      const myLine = this.echarts.init(document.getElementById("myline"));
      const option = {
        legend: {
          data: ["商贩事件", "餐馆事件", "违章事件", "PM2.5事件"]
        },
        grid: {
          containLabel: true
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
        },
        yAxis: {
          type: "value"
        },
        series: [
          {
            name: "商贩事件",
            type: "line",
            stack: "总量",
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: "餐馆事件",
            type: "line",
            stack: "总量",
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: "违章事件",
            type: "line",
            stack: "总量",
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: "PM2.5事件",
            type: "line",
            stack: "总量",
            data: [320, 332, 301, 334, 390, 330, 320]
          }
        ]
      };
      myLine.setOption(option);
    },
    mybar() {
      const myBar = this.echarts.init(document.getElementById("mybar"));
      const option = {
        legend: {},
        tooltip: {},
        dataset: {
          source: [
            ["product", "总事件", "处理事件", "未处理事件"],
            ["商贩事件", 43.3, 85.8, 93.7],
            ["餐馆事件", 83.1, 73.4, 55.1],
            ["违章事件", 86.4, 65.2, 82.5],
            ["PM2.5事件", 72.4, 53.9, 39.1]
          ]
        },
        xAxis: { type: "category" },
        yAxis: {},
        series: [
          {
            type: "bar",
            label: {
              normal: {
                show: true,
                position: "top"
              }
            }
          },
          {
            type: "bar",
            label: {
              normal: {
                show: true,
                position: "top"
              }
            }
          },
          {
            type: "bar",
            label: {
              normal: {
                show: true,
                position: "top"
              }
            }
          }
        ]
      };
      myBar.setOption(option);
    }
  }
};
</script>

<style scoped>
.wrap {
  padding-top: 8vh;
  margin: 0 auto;
  text-align: center;
}
.card {
  width: 35vw;
  height: 70vh;
  margin-left: 3vw;
  display: inline-block;
}
#myline {
  width: 100%;
  height: 100%;
}
#mybar {
  width: 100%;
  height: 100%;
}
</style>